package cn.yesway.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.yesway.dao.AcctUserDao;
import cn.yesway.entity.AcctUser;
import cn.yesway.service.AcctUserService;

@Service
public class AcctUserServiceImpl implements AcctUserService {
	@Autowired
	private AcctUserDao acctUserDao;

	// 新增用户
	public void saveUser(AcctUser acctUser) {
		acctUserDao.save(acctUser);
	}

	public AcctUser getUserById(Long userId) {
		return acctUserDao.findOne(userId);
	}

	public AcctUser findByLoginName(String loginName) {
		return acctUserDao.findByLoginName(loginName);
	}

	public AcctUser findByLoginNameIgnoreCase(String loginName) {
		return acctUserDao.findByLoginNameIgnoreCase(loginName);
	}

	public AcctUser findByLoginNameAndPassword(String loginName, String password) {
		return acctUserDao.findByLoginNameAndPassword(loginName, password);
	}

	public List<AcctUser> findByLoginNameOrEmail(String loginName, String email) {
		return acctUserDao.findByLoginNameOrEmail(loginName, email);
	}

	public List<AcctUser> findByEmailOrderByLoginNameAsc(String email) {
		return acctUserDao.findByEmailOrderByLoginNameAsc(email);
	}

	public AcctUser findFirstByEmailOrderByLoginNameAsc(String email) {
		return acctUserDao.findFirstByEmailOrderByLoginNameAsc(email);
	}

	public List<AcctUser> findByEmail(String email, Sort sort) {
		return acctUserDao.findByEmail(email, sort);
	}

	public List<AcctUser> findDistinctByEmail(String email) {
		return acctUserDao.findDistinctByEmail(email);
	}

	public Page<AcctUser> findByEmail(String email, Pageable pageable) {
		return acctUserDao.findByEmail(email, pageable);
	}

	public Page<AcctUser> findAll(Pageable pageable) {
		return acctUserDao.findAll(pageable);
	}
	
	public List<AcctUser> findAll(Sort sort) {
		return acctUserDao.findAll(sort);
	}
	
	public Long countByEmail(String email) {
		return acctUserDao.countByEmail(email);
	}

	// 此处必须加@Transactional，否则不能运行，报错，或加在dao层
	@Transactional
	public int updateLoginTime(long acctUserId, Date loginTime) {
		return acctUserDao.updateLoginTime(acctUserId, loginTime);
	}

	@Transactional
	public int deleteByIds(List<Long> ids) {
		return acctUserDao.deleteByIds(ids);
	}

	@Transactional
	public Long deleteByEmail(String email) {
		return acctUserDao.deleteByEmail(email);
	}

	@Transactional
	public List<AcctUser> removeByEmail(String email) {
		return acctUserDao.removeByEmail(email);
	}
}
